/**
 * @file   1022.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Fri Jul 23 23:07:11 2021
 * 
 * @brief  PAT advanced 1022
 * 
 * 
 */
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<map>
using namespace std;
class library{
private:
    map<string,set<string>> bookname,author,keyword,publisher,repyear;
    int querynum;
    int booknum;
public:
    library();//Build the library!
    void quiry(map<string,set<string>>& mp,string& str);
    void solve();
};
library::library(){
    cin>>booknum;
    for(int i=0;i<booknum;i++){
	string id,_title,_author,_publisher,_repyear,_keyword;
	cin>>id;
	getchar();
	getline(cin,_title);bookname[_title].insert(id);
	getline(cin,_author);author[_author].insert(id);
	while(cin>>_keyword){
	    keyword[_keyword].insert(id);
	    if(getchar()=='\n'){
		break;
	    }
	}
	getline(cin,_publisher);publisher[_publisher].insert(id);
	getline(cin,_repyear);repyear[_repyear].insert(id);
    }
    cin>>querynum;
    getchar();
}
void library::solve(){
    for(int i=0;i<querynum;i++){
	int type;
	scanf("%d: ",&type);
	string str;
	getline(cin,str);
	cout<<type<<": "<<str<<endl;
	switch(type){
	case 1:
	    quiry(bookname,str);
	    break;
	case 2:
	    quiry(author,str);
	    break;
	case 3:
	    quiry(keyword,str);
	    break;
	case 4:
	    quiry(publisher,str);
	    break;
	case 5:
	    quiry(repyear,str);
	    break;
	}
    }
}
void library::quiry(map<string,set<string>>& mp,string& str){
    if(mp.find(str)!=mp.end()){
	for(auto it=mp[str].begin();it!=mp[str].end();it++){
	    cout<<*it<<endl;
	}
    }else{
	cout<<"Not Found"<<endl;
    }
}
int main(){
    library ZJUlib;
    ZJUlib.solve();
}
